package com.netty.socket.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2018/9/9/009.
 */
public class SourceClient {
    public static void main(String[] args) {
        EventLoopGroup enveLoopGroup = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();

            bootstrap.group(enveLoopGroup).channel(NioSocketChannel.class);
            bootstrap.handler(new SourceClientInitializer());

            ChannelFuture channelFuture = bootstrap.connect("localhost", 8899).sync();
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            Channel channel = channelFuture.channel();
            for (; ; ) {
                channel.writeAndFlush(br.readLine() + "\r\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            enveLoopGroup.shutdownGracefully();
        }

    }
}
